package com.pengtgimust.androidvideoplayer;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.View;
import android.widget.Toast;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class XPlay extends GLSurfaceView implements GLSurfaceView.Renderer,SurfaceHolder.Callback, View.OnClickListener {
    public long firstTime = 0L;
    public long secondTime = 0L;
    public Context mContext;

    public XPlay(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        setRenderer(this);
        setOnClickListener(this);
    }
    @Override
    public void surfaceCreated(SurfaceHolder holder){
        //初始化opengl egl 显示
        InitView(holder.getSurface());


    }
    @Override
    public void surfaceChanged(SurfaceHolder var1, int var2, int var3, int var4){

    }
    @Override
    public void surfaceDestroyed(SurfaceHolder var1){

    }

    public native void InitView(Object surface);

    @Override
    public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {

    }

    @Override
    public void onSurfaceChanged(GL10 gl10, int i, int i1) {

    }

    @Override
    public void onDrawFrame(GL10 gl10) {

    }

    @Override
    public void onClick(View view) {
        if(firstTime == 0){

            this.firstTime = System.currentTimeMillis();
            return;
        }
//        if(secondTime == 0)
//        {
//            this.secondTime = System.currentTimeMillis();
//        }
        if (System.currentTimeMillis() - this.firstTime < 500L)
        {
            PlayOrPause();
            this.firstTime = 0;
        }else {
            this.firstTime = 0;
            Toast.makeText(mContext, "双击屏幕 播放/暂停", Toast.LENGTH_SHORT).show();
        }
    }
    public native void PlayOrPause();
}
